


/**
* @file msg.h
* @brief 消息封装
* @author zshare
* @version v1.0
* @date 2022-03-11
* @history  
*/


#ifndef __MSG__H__
#define __MSG__H__


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*=========================通用类==========================*/
#define _log_
#ifdef _log_
	#define log_print(format, arg...) printf(format,## arg)
#else
	#define log_print(format, arg...) do{}while(0)
#endif
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
#define nil NULL
#define FALSE 1
#define TRUE 0
#define CMD_GET_VERSION 0x01
#define pcalloc(x,size,type) do{ if((x = (type *)calloc(1,size)) == NULL){ return FALSE; } }while(0)
#define pfree(ptr) do{ if(ptr != NULL) { free(ptr); } ptr = NULL; }while(0)



/*=========================消息类==========================*/
#define test_rev_chan	"/dev/chan_0"
#define test_snd_chan	"/dev/chan_1"
#define MSG_PRIORITY_GENERAL 0	//普通消息
#define MSG_PRIORITY_URGENCY 1	//紧急消息

typedef struct {
	u8 dst;//目的地址
	u8 src;//源地址
	u8 priority;//优先级
	u8 type;//消息类别
}head_st;

typedef struct {
	u32 len;//消息体长度
	u8 *data;//消息内容
}body_st;

//消息格式
typedef struct {
	head_st header;
	body_st body;
}msg_st;

#define msg_len(msg)	(sizeof(head_st)+sizeof(u32)+msg->body.len)


#define BOB	0x01



#define MSG_TYPE_STATE	0x01

u32 pack_msg(u8 dst, u8 src, u8 prio, u8 type, u32 len, u8 *data, msg_st **pmsg);



#endif


















